package com.bbx.taxi.client.Adapter.Unprocessed;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.View.OnTouchListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bbx.androidapi.util.ToastUtil;
import com.bbx.api.sdk.model.official.passanger.Return.OrderList.UnprocessedList.UnprocessedList;
import com.bbx.api.sdk.model.passanger.Return.MyOrderList.MyOrderList;
import com.bbx.taxi.client.Adapter.MyOrderAdapter.ViewHolder;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.DB.LineDB;
import com.bbx.taxi.client.DB.UnprocessedList.UnprocessedListDB;
import com.bbx.taxi.client.DB.UnprocessedList.UnprocessedRecordDB;
import com.bbx.taxi.client.Util.FormatUtil;
import com.bbx.taxi.client.widget.MyViewPager;
import com.bbx.taxi.official.R;
/** 
 * @Path com.bbx.taxi.client.Adapter.Unprocessed.UnprocessedRecordAdapter.java
 * @Author 严旭文
 * @Date 2016-1-26 下午6:03:22
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 */
public class UnprocessedRecordAdapter  extends BaseAdapter {
	private ArrayList<UnprocessedList> list;
	private Activity context;
	private MyViewPager mViewPager;

	public UnprocessedRecordAdapter(Activity context, ArrayList<UnprocessedList> list) {
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;

	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder viewholder;
		if (convertView == null) {
			LayoutInflater inflater = LayoutInflater.from(context);
			convertView = (View) inflater.inflate(R.layout.listitem_unprocessedrecord,
					null);
			viewholder = new ViewHolder();
			viewholder.tv_ispass=(TextView)convertView
					.findViewById(R.id.tv_ispass);
			viewholder.tv_name = (TextView) convertView
					.findViewById(R.id.tv_name);
			viewholder.time = (TextView) convertView.findViewById(R.id.time);
			viewholder.tv_tel = (TextView) convertView
					.findViewById(R.id.tv_tel);
			viewholder.start_address = (TextView) convertView
					.findViewById(R.id.start_address);
			viewholder.end_address = (TextView) convertView
					.findViewById(R.id.end_address);
			viewholder.tv_price = (TextView) convertView
					.findViewById(R.id.tv_price);
			viewholder.layout_item = (LinearLayout) convertView
					.findViewById(R.id.layout_item);
			viewholder.layout_ispass = (LinearLayout) convertView
					.findViewById(R.id.layout_ispass);
			convertView.setTag(viewholder);
			
		} else
			viewholder = (ViewHolder) convertView.getTag();
		
		String ispass=list.get(position).getProcessResult();
		if(ispass.equals(Value.PROCESS_RESULT_PASS)){
			viewholder.tv_ispass.setText(context.getString(R.string.has_pass));
			viewholder.layout_ispass.setBackgroundResource(R.drawable.icon_dd_label3);
		}else{
			viewholder.tv_ispass.setText(context.getString(R.string.has_reject));
			viewholder.layout_ispass.setBackgroundResource(R.drawable.icon_dd_label1);
		}
		
		viewholder.tv_price.setText(String.format(context
				.getString(R.string.orderlist_price), FormatUtil
				.onFormatPrice(list.get(position).getOrderInfo().getPrice())));
		viewholder.tv_name.setText(list.get(position).getOrderDetail().getStart()
				.getName());
		viewholder.tv_tel.setText(list.get(position).getOrderDetail().getStart()
				.getPhone());
		viewholder.time.setText(list.get(position).getOrderInfo().getAppoint_time());
		viewholder.start_address
				.setText(list.get(position).getOrderDetail().start.address);
		viewholder.end_address
				.setText(list.get(position).getOrderDetail().end.address);

		viewholder.layout_item.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if (mViewPager != null)
					mViewPager.setNoScroll(true);

				return false;
			}
		});
		return convertView;

	}

	public class ViewHolder {
		TextView time, start_address, end_address, tv_price, tv_name, tv_tel,tv_ispass;
		LinearLayout layout_item;
		LinearLayout layout_ispass;
	}

	Handler mHandler = new Handler() {
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 0:
				// context.startActivity(new Intent(context,
				// AddAddressActivity.class));
				break;
			}
		};
	};
}
